﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm2
{
    class TrafficJam
    {
        public TrafficJam()
        {
            int testCase = Int32.Parse(Console.ReadLine());
            while (testCase-- > 0)
            {
                string[] consoleInput = Console.ReadLine().Split(' ');
                int size = Int32.Parse(consoleInput[0]);
                int[] boxes = new int[100001];
                int maxNum = 1;
                for (int i = 1; i <= size; i++)
                {
                    int number = Int32.Parse(consoleInput[i]);
                    if (number > maxNum)
                    { maxNum = number; }
                    boxes[number] = i;
                }
                int bigNum = 0;
                int diff = 0;
                int count = 0;
                int startNumber = 1;
                bool findNeedMove = true;
                while (findNeedMove)
                {
                    count++;
                    findNeedMove = false;
                    for (int i = startNumber; i <= maxNum; i++)
                    {
                        if (findNeedMove)
                        {
                            boxes[i] += diff;
                        }
                        else if (boxes[i] > bigNum)
                        {
                            bigNum = boxes[i];
                        }
                        else
                        {
                            findNeedMove = true;
                            diff = bigNum - boxes[i] + 1;
                            boxes[i] += diff;
                            startNumber = i + 1;
                            bigNum = boxes[i];
                        }
                    }
                }
                Console.WriteLine(count - 1);
            }
        }
    }
}
